import { createStore } from 'vuex'
import { useRouter } from "vue-router";
export default createStore({
    state: {
        isCollapse: true,
        currentMenu: null,
        tabsList: [
            {
                path: '/',
                name: "home",
                label: '首页',
                icon: 'home'
            }
        ],
    },
    mutations: {
        updateIsCollapse(state, payload) {
            state.isCollapse = !state.isCollapse
        },
        selectMenu(state, payload) {
            // payload.name == "home" ? state.currentMenu = null : state.currentMenu = payload
            if (payload.name == 'home') {
                state.currentMenu = null
            } else {
                state.currentMenu = payload
                let result = state.tabsList.findIndex(item => item.name == payload.name)
                result == -1 ? state.tabsList.push(payload) : ''
            }
        },
        closeTab(state, payload) {
            let res = state.tabsList.findIndex(item => item.name == payload.name)
            state.tabsList.splice(res, 1)
        }
    }
})